package com.cos.hospital.ui.record.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.cos.hospital.R;
import com.cos.hospital.code.BedType;
import com.cos.hospital.model.bean.BedBean;
import com.cos.hospital.widget.baseadapter.RecyclerBaseAdapter;
import com.cos.hospital.widget.baseadapter.RecyclerViewHolder;

import java.util.List;

public class BedAdapter extends RecyclerBaseAdapter<BedBean> {
    public BedAdapter(@NonNull Context context, @NonNull List<BedBean> mDataList) {
        super(context, mDataList);
    }



    @Override
    protected void bindDataForView(RecyclerViewHolder holder, BedBean bedBean, int position) {
        ImageView bedI = holder.getView(R.id.bed_icon);
        TextView textYes = holder.getView(R.id.bed_text_yes);
        TextView textNo = holder.getView(R.id.bed_text_no);
        int adapterPosition = holder.getAdapterPosition()+1;
        String number = String.valueOf(adapterPosition);
        textYes.setText(number);
        if (bedBean.getFldState() == BedType.ENABEL_NO) {
            bedI.setEnabled(false);
            textNo.setVisibility(View.VISIBLE);
            textYes.setVisibility(View.GONE);
            textNo.setText(number);
        } else if (bedBean.getFldState() == BedType.ENABEL_YES) {
            bedI.setEnabled(true);
            textNo.setVisibility(View.GONE);
            textYes.setVisibility(View.VISIBLE);
            if (bedBean.getaBoolean()) {
                bedI.setSelected(true);
            } else {
                bedI.setSelected(false);
            }
            //  textYes.setSelected(false);
            //  helper.setText(R.id.bed_text_yes, item.getFldBedNum());
        }
    }

    @NonNull
    @Override
    public RecyclerViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(getContext()).inflate(R.layout.item_bed, null, false);
        return new RecyclerViewHolder(view);
    }

}
/*    public int selectPosition = -1;

    public BedAdapter(@Nullable List<BedBean> data) {
        super(R.layout.item_bed, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, BedBean item) {
        ImageView bedI = helper.getView(R.id.bed_icon);
        TextView textYes = helper.getView(R.id.bed_text_yes);
        TextView textNo = helper.getView(R.id.bed_text_no);
        int adapterPosition = helper.getAdapterPosition()+1;
        String number = String.valueOf(adapterPosition);
        textYes.setText(number);
        if (item.getFldState() == BedType.ENABEL_NO) {
            bedI.setEnabled(false);
            textNo.setVisibility(View.VISIBLE);
            textYes.setVisibility(View.GONE);
            helper.setText(R.id.bed_text_no, number);
        } else if (item.getFldState() == BedType.ENABEL_YES) {
            bedI.setEnabled(true);
            textNo.setVisibility(View.GONE);
            textYes.setVisibility(View.VISIBLE);
            if (item.getaBoolean()) {
                bedI.setSelected(true);
            } else {
                bedI.setSelected(false);
            }
            //  textYes.setSelected(false);
            //  helper.setText(R.id.bed_text_yes, item.getFldBedNum());
        } *//*else if (item.getFldState() == BedType.ENABEL_SELECT) {
            bedI.setEnabled(true);
            bedI.setSelected(true);
            textNo.setVisibility(View.GONE);
            textYes.setVisibility(View.VISIBLE);
            helper.setText(R.id.bed_text_yes, item.getFldBedNum());
            textYes.setSelected(true);
        }*//*
    }

    public void setItemUpdate(int position) {
        if (getData().get(position).getFldState() != BedType.ENABEL_NO) {
            BedBean bedBean = getData().get(position);
            if (bedBean.getaBoolean()) {
                bedBean.setaBoolean(false);
            } else {
                bedBean.setaBoolean(true);
            }
      *//*      if (selectPosition == position) {
                getData().get(position).setFldState(BedType.ENABEL_YES);
                selectPosition = -1;
            } else {
                if (selectPosition == -1) {
                    getData().get(position).setFldState(BedType.ENABEL_SELECT);
                } else {
                    getData().get(selectPosition).setFldState(BedType.ENABEL_YES);
                    getData().get(position).setFldState(BedType.ENABEL_SELECT);
                }
                selectPosition = position;
            }*//*

            notifyDataSetChanged();
        }
    }*/

